/**
 * *****************************************************************************
 * @file    main.c
 * @author  Home(zhhuang@andartechs.com.cn)
 * @version 0.1
 * @date    2021-11-10
 * @brief
 * 
 *                 Copyright (c) 2021, Andar Technologies Inc.
 *                           www.andartechs.com
 * 
 * *****************************************************************************
 */
#include "CM3DS_MPS2.h"
#include "stdio.h"
#include "math.h"
#include "adt3102.h"
#include "adt3102_system.h"
#include "adt3102_tx.h"
#include "adt3102_rx.h"
#include "adt3102_pmu.h"
#include "adt3102_timer.h"
#include "adt3102_dsp.h"
#include "adt3102_gpio.h"
#include "adt3102_memscheduling.h"
#include "adt3102_phase_cal.h"
#include "adt3102_type_define.h"
#include "adt3102_uart.h"
#include "adt3102_system.h"
#include "adt3102_rtc.h"
#include "adt3102_sagc.h"
#include "adt3102_trng.h"
#include "adt3102_watchdog.h"
#include "pmu_ctype_map.h"
#include "rfc_ctype_map.h"
#include "dsp_ctype_map.h"
#include "rtc_ctype_map.h"
#include "static_remove.h"
#include "peak_single.h"
#include "gpio_ctype_map.h"
#include "adt3102_uart.h"
#include "adt3102_tinyframe.h"
#include "adt3102_utilities.h"
#include "adt3102_spi.h"
#include "adt3102_flash.h"

#include "adt3102_init.h"
#include "common.h"
#include "scan.h"
#include "spi_acquisition.h"



/*------------------------ static ------------------------*/
static uint8                        s_version_major;
static uint8                        s_version_minor;
static uint8                        s_version_patch;
static verStatusStrTypedef          s_verStatus;
static TinyFrameRxStrTypedef        s_revTestStr;
static uint32 s_curTiaGain = 0;
static uint32 s_curVgaGain = 0;

static AnalogDataStrTypedef         s_analogDataStr;

static void init(void);


/*------------------------------ function ------------------------------------*/

/**
 * @brief   The entry point of the program.
 * @param   None.
 * @return  int:
 * @note
 */
int main(void)
{
    //--- for power mode test. 
    //pmuSleepTest();
    //pmuIdleTest();
    //pmuActiveTest();
    
    /* The interrupt vector table must be placed at the front of the
        main function, otherwise the OTA upgrade will no work. */
    MY_NVIC_SetVectorTable(0x00000000, 0x8000);
    s_version_major = 1;
    s_version_minor = 0;
    s_version_patch = 0;

    tinyFrameInit();


    /*----- Initialize some basic functions --------------*/
    adt3102ScanInit();
    adt3102SystemInit();
    //adt3102ValInit(&s_analogDataStr);
    adt3102ModuleInit();
    dataAcquisitonSpiInit(SPI0, SPI_MASTER_MODE);

    printfTf("ADT3102 data acquisition V%d.%d.%d \r\n", \
        s_version_major, s_version_minor, s_version_patch);

    while(1) //repeat sending chirps
    {
        adcSample();
    }
}
